const EOF = Symbol('EOF');

function data(c) {
    if( c == '<') {
        return tagOpen;
    } else if ( c == EOF) {
        emit({
            type:"EOF"
        })
        return ;
    } else {
        emit({
            type:"text",
            content:c
        })
        return data;
    }
}

function tagOpen(c) {
    if(c == '/') {
        return endTagOpen;
    } else if( c.match(/^[a-zA-Z]$/)) {
        currentToken = {
            type: "startTag",
            tagName : ''
        }
        return tagName(c);
    } else {
        return ;
    }
}


function endTagOpen(c) {
    if( c.match(/^[a-zA-Z]$/)){
        currentToken = {
            type: "endTag",
            tagName: "",
        }
        return tagName(c);
    } else if(c == '>') {
        
    } else if(c == EOF){

    } else {

    }
}

function tagName(c) {
    if( c.match(/^[\t\n\f ]$/)){
        return beforeAttributeName;
    } else if(c == '/'){
        return selfClosingStartTag;
    } else if(c.match(/^[a-zA-Z]$/)){
        currentToken.tagName += c //.toLowerCase();
        return tagName;
    } else if(c == '>'){
        return data;
    } else {
        return tagName;
    }
}

let currentAttribute;

function beforeAttributeName(c) {
    if(c.match(/^[\t\n\f ]$/)) {
        return beforeAttributeName;
    } else if(c == '>' || c == '/' || c == EOF){
        return afterAttributeName(c);
    } else if(c == '=') {
        return beforeAttributeName;
    } else {
        currentAttribute = {
            name: "",
            value: ""
        }
        return attributeName(c);
    }
}


function attributeName(c) {
    if(c.match(/^[\t\n\f ]$/) || c == "/" || c == ">" || c == EOF) {
        return afterAttributeName(c);
    } else if(c == '=') {
        return beforeAttributeValue;
    } else if( c == '\u0000') {

    } else if(c == "\"" || c == "'" || c== "<") {

    } else {
        currentAttribute.name += c;
        return attributeName;
    }
}

function afterAttributeName(c){

}

let currentToken = null;

function selfClosingStartTag(c) {
    if (c == '>') {
        currentToken.isSelfClosing = true;
    } else if(c == 'EOF') {

    } else {
        
    }
}

function emit(token){
    console.log(token);
}

module.exports.parseHTML = function parseHTML(html){
    console.log(html);
    let state = data;

    for(let c of html) {
        state = state(c);
    }

    state = state(EOF);
}